//
//  ViewController.m
//  解释器模式
//
//  Created by flannery on 2018/12/19.
//  Copyright © 2018年 flannery. All rights reserved.
//

#import "ViewController.h"
#import "Expression.h"

@interface ViewController ()

@end

@implementation ViewController

// 规则：Robert 和 John 是男性
- (Expression*)getMaleExpression{
    Expression *robert = [[TerminalExpression alloc]initWithExpression:@"Robert"];
    Expression *john = [[TerminalExpression alloc] initWithExpression:@"John"];
    return [[OrExpression alloc]initWithExpression1:robert expression2:john];
}

- (Expression*)getMarriedWomanExpression{
    Expression *julie = [[TerminalExpression alloc]initWithExpression:@"Julie"];
    Expression *married = [[TerminalExpression alloc] initWithExpression:@"Married"];
    return [[AndExpression alloc]initWithExpression1:julie expression2:married];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Expression *isMale =  [self getMaleExpression];
    Expression *isMarriedWomen = [self getMarriedWomanExpression];
    NSLog(@"John is male? %d", [isMale interpret:@"John"]);
    NSLog(@"Julie is a married women? %d", [isMarriedWomen interpret:@"Married Julie"]);
}


@end
